package net.minecraft.src;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class BlockInvisibleRedTorch extends BlockRedstoneTorch {
	
	public BlockInvisibleRedTorch (int i, int j, boolean k) {
		super(i, j, k);
		maxTick = 10;
		startTick = 0;
	}
	
	public int idDropped(int i, Random random)
    {
        return 0;
    }
	
	public void randomDisplayTick(World world, int i, int j, int k, Random random)
    {
		//existence tick
        startTick += 2;
        if(startTick >= maxTick){
        	world.setBlockWithNotify(i, j, k, 0);
        	startTick = 0;
        }
    }
	
	private boolean func_30002_h(World world, int i, int j, int k)
    {
        int l = world.getBlockMetadata(i, j, k);
        if(l == 5 && world.isBlockIndirectlyProvidingPowerTo(i, j - 1, k, 0))
        {
            return true;
        }
        if(l == 3 && world.isBlockIndirectlyProvidingPowerTo(i, j, k - 1, 2))
        {
            return true;
        }
        if(l == 4 && world.isBlockIndirectlyProvidingPowerTo(i, j, k + 1, 3))
        {
            return true;
        }
        if(l == 1 && world.isBlockIndirectlyProvidingPowerTo(i - 1, j, k, 4))
        {
            return true;
        }
        return l == 2 && world.isBlockIndirectlyProvidingPowerTo(i + 1, j, k, 5);
    }
	
	public void updateTick(World world, int i, int j, int k, Random random)
    {
        boolean flag = func_30002_h(world, i, j, k);
        for(; torchUpdates.size() > 0 && world.getWorldTime() - ((RedstoneUpdateInfo)torchUpdates.get(0)).updateTime > 100L; torchUpdates.remove(0)) { }
        if(torchActive)
        {
            if(flag)
            {
                world.setBlockAndMetadataWithNotify(i, j, k, 0, world.getBlockMetadata(i, j, k));
                if(checkForBurnout(world, i, j, k, true))
                {
                    for(int l = 0; l < 5; l++)
                    {
                    }

                }
            }
        } else
        if(!flag && !checkForBurnout(world, i, j, k, false))
        {
        }
    }
	
	private boolean checkForBurnout(World world, int i, int j, int k, boolean flag)
    {
        if(flag)
        {
            torchUpdates.add(new RedstoneUpdateInfo(i, j, k, world.getWorldTime()));
        }
        int l = 0;
        for(int i1 = 0; i1 < torchUpdates.size(); i1++)
        {
            RedstoneUpdateInfo redstoneupdateinfo = (RedstoneUpdateInfo)torchUpdates.get(i1);
            if(redstoneupdateinfo.x == i && redstoneupdateinfo.y == j && redstoneupdateinfo.z == k && ++l >= 8)
            {
                return true;
            }
        }

        return false;
    }
	
	private int maxTick;
	private int startTick;
	
	private boolean torchActive;
	private static List torchUpdates = new ArrayList();
	
}
